package ca.quicko.dao.jpa;

import java.util.List;

import javax.persistence.Query;

import org.appfuse.dao.jpa.GenericDaoJpa;

import ca.quicko.dao.IssueDao;
import ca.quicko.model.Issue;

/**
 * @author <a href="mailto:eric.s.landry@gmail.com">Eric S. Landry</a>
 */
public class IssueDaoJpa extends GenericDaoJpa<Issue, Long> implements IssueDao {
	public IssueDaoJpa() {
		super(Issue.class);
	}

	@SuppressWarnings("unchecked")
	public List<Issue> findByTitle(String title) {
		Query q = super.entityManager
				.createQuery("select i from Issue i where i.title=?");
		q.setParameter(1, title);
		return q.getResultList();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Issue> getAll() {
		return this.entityManager.createQuery(
				"select obj from Issue obj where obj.active=true")
				.getResultList();
	}

	@Override
	public void remove(Long id) {
		Issue issue = get(id);
		issue.setActive(false);
		save(issue);
	}
}
